<template>
<div id="test">
    <div id="side-menu">
        <Menu id="left-menu" mode="vertical" :theme="theme2">
            <Submenu name="1">
                <template slot="title">
                    <Icon type="ios-bookmark" />
                    常用操作
                </template>
                <MenuItem name="1-1" @click.native="init">初始化插件</MenuItem>
                <MenuItem name="1-2" @click.native="createDocument">新建文档</MenuItem>
                <MenuItem name="1-3" @click.native="fullScreen">全屏【CTRL+Q退出】</MenuItem>
                <MenuItem name="1-4" @click.native="wpsclose">关闭文档</MenuItem>
                <MenuItem name="1-5" @click.native="disable_ctrl_p">禁用ctrl+p</MenuItem>
                <MenuItem name="1-6" @click.native="enable_ctrl_p">启用ctrl+p</MenuItem>
                <MenuItem name="1-7" @click.native="insert_document">insert_document</MenuItem>
                <MenuItem name="1-8" @click.native="wpsprint">打印</MenuItem>
                <MenuItem name="1-9" @click.native="printRevision">打印/不打印修订文字</MenuItem>
                <MenuItem name="1-10" @click.native="enableProtectT">保护文档</MenuItem>
                <MenuItem name="1-11" @click.native="enableProtectF">停止保护</MenuItem>
            </Submenu>
            <Submenu name="2">
                <template slot="title">
                    <Icon type="ios-bookmark" />
                    操作本地文档
                </template>
                <MenuItem name="2-1" @click.native="openDocumentT">只读打开本地文档</MenuItem>
                <MenuItem name="2-2" @click.native="openDocumentF">可编辑打开本地文档</MenuItem>
                <MenuItem name="2-3" @click.native="saveAs">保存到本地</MenuItem>
            </Submenu>
            <Submenu name="3">
                <template slot="title">
                    <Icon type="ios-bookmark" />
                    操作远程文档
                </template>
                <MenuItem name="3-1" @click.native="openDocumentRemote">打开远程文档</MenuItem>
                <MenuItem name="3-2" @click.native="saveURL">保存到远程</MenuItem>
                <MenuItem name="3-3" @click.native="SendDataToServer">本地文档保存到远程</MenuItem>
                <MenuItem name="3-4" @click.native="saveURL2">保存到远程_pdf加密</MenuItem>
                <MenuItem name="3-5" @click.native="saveURL3">保存到远程_包含设置pdf选项</MenuItem>
                <MenuItem name="3-6" @click.native="saveURL4">保存到远程_导出pdf嵌入字体</MenuItem>
                <MenuItem name="3-5" @click.native="DownLoadServerFile">下载</MenuItem>
            </Submenu>
            <Submenu name="4">
                <template slot="title">
                    <Icon type="ios-bookmark" />
                    显示隐藏操作项
                </template>
                <MenuItem name="4-1" @click.native="setToolbarAllVisibleF">隐藏全部工具菜单</MenuItem>
                <MenuItem name="4-2" @click.native="setToolbarAllVisibleT">显示全部工具菜单</MenuItem>
                <MenuItem name="4-3" @click.native="SetFileSubmenuItemsVisible_new">显示新建</MenuItem>
                <MenuItem name="4-4" @click.native="SetFileSubmenuItemsHidden_new">隐藏新建</MenuItem>
                <MenuItem name="4-5" @click.native="SetFileSubmenuItemsVisible_open">显示打开</MenuItem>
                <MenuItem name="4-6" @click.native="SetFileSubmenuItemsHidden_open">隐藏打开</MenuItem>
                <MenuItem name="4-7" @click.native="SetFileSubmenuItemsVisible_close">显示关闭</MenuItem>
                <MenuItem name="4-8" @click.native="SetFileSubmenuItemsHidden_close">隐藏关闭</MenuItem>
                <MenuItem name="4-9" @click.native="SetFileSubmenuItemsVisible_save">显示保存</MenuItem>
                <MenuItem name="4-10" @click.native="SetFileSubmenuItemsHidden_save">隐藏保存</MenuItem>
                <MenuItem name="4-11" @click.native="SetFileSubmenuItemsVisible_saveAs">显示另存</MenuItem>
                <MenuItem name="4-12" @click.native="SetFileSubmenuItemsHidden_saveAs">隐藏另存</MenuItem>
                <MenuItem name="4-13" @click.native="SetFileSubmenuItemsVisible_pageSetup">显示页面设置</MenuItem>
                <MenuItem name="4-14" @click.native="SetFileSubmenuItemsHidden_pageSetup">隐藏页面设置</MenuItem>
                <MenuItem name="4-15" @click.native="SetFileSubmenuItemsVisible_printpy">显示打印预览</MenuItem>
                <MenuItem name="4-16" @click.native="SetFileSubmenuItemsHidden_printpy">隐藏打印预览</MenuItem>
                <MenuItem name="4-17" @click.native="SetFileSubmenuItemsVisible_print">显示打印</MenuItem>
                <MenuItem name="4-18" @click.native="SetFileSubmenuItemsHidden_print">隐藏打印</MenuItem>
                <MenuItem name="4-19" @click.native="SetFileSubmenuItemsVisible_property">显示属性</MenuItem>
                <MenuItem name="4-20" @click.native="SetFileSubmenuItemsHidden_property">隐藏属性</MenuItem>
            </Submenu>
        </Menu>       
    </div>
    <div id="wps-content">
        <div id="wps"></div>
    </div>
</div>
</template>

<script>
import {wps_init} from '../api/wps.js'

var DocFrame;
var MenuItems = { FILE: 1 << 0, EDIT: 1 << 1, VIEW: 1 << 2, INSERT: 1 << 3, FORMAT: 1 << 4, TOOL: 1 << 5, CHART: 1 << 6, HELP: 1 << 7 };
var FileSubmenuItems = { NEW: 1 << 0, OPEN: 1 << 1, CLOSE: 1 << 2, SAVE: 1 << 3, SAVEAS: 1 << 4, PAGESETUP: 1 << 5, PRINTPY: 1 << 6, PRINT: 1 << 7, PROPERTY: 1 << 8 };

export default {
    name: "wps",
    data() {
        return {
            theme2: 'dark'
        }
    },
    methods: {
        init() {    //初始化插件
            DocFrame = wps_init("wps", "100%", "100%");
        },
        createDocument() {  //新建文档
            DocFrame.createDocument("uot");
        },
        fullScreen() {  //全屏
            DocFrame.FullScreen();
        },
        wpsclose() { //关闭文档
            var aa = DocFrame.close();
            alert(aa);
        },
        disable_ctrl_p() {  //禁用ctrl+p
            DocFrame.DisabledHotKeys = "(ctrl+p)";
        },
        enable_ctrl_p() {   //启用 ctrl+p
            DocFrame.DisabledHotKeys = "";
        },
        insert_document() { //insert
            alert(DocFrame.insertDocument('正文', 'ftp://ftptest:123456@192.168.158.73/test/ftp.doc'));
        },
        wpsprint() {    //打印
            var aa = DocFrame.print();
            alert(aa);
        },
        printRevision() {   //打印/不打印修订文字
            var aa = DocFrame.printRevision(0);
            alert(aa);
        },
        enableProtectT() {  //保护文档
            var aa = DocFrame.enableProtect(true);
            alert(aa);
        },
        enableProtectF() {  //停止保护
            var aa = DocFrame.enableProtect(false);
            alert(aa);
        },
        openDocumentT() {   //只读打开本地文档
            var path = prompt("请输入要打开的名称", "D:\\000001.wps");
            if (path != null && path != "") {
                var aa = DocFrame.openDocument(path, true);
                alert(aa);
            }
        },
        openDocumentF() {
            //var aa = DocFrame.openDocument('C:\\Users\\Administrator\\Desktop\\1.wps',false);
            var path = prompt("请输入要打开的名称", "D:\\000001.wps");
            if (path != null && path != "") {
                var aa = DocFrame.openDocument(path, false);
                alert(aa);
            }
        },
        saveAs() {  //另存为
            var path = prompt("请输入要保存的名称", "D:\\test.pdf");
            if (path != null && path != "") {
                var aa = DocFrame.saveAs(path);
                alert(aa);
            }
        },
        openDocumentRemote() {  //打开远程文档
            var path = prompt("请输入要打开的名称", "http://192.168.137.132:8080/wps/test1105.wps");
            if (path != null && path != "") {
                var aa = DocFrame.openDocumentRemote(path, false);
                alert(aa);
            }
        },
        saveURL() {     //保存到远程
            var name = prompt("请输入要保存的名称", "test1.ofd")
            if (name != null && name != "") {
                var ret = DocFrame.saveURL("http://192.168.41.128:8080/wps/upload_w.jsp", name);
                alert(ret);
            }
        },
        SendDataToServer() {    //本地文档保存到远程
            var aa = DocFrame.SendDataToServer("http://192.168.41.128:8080/wps/upload_w.jsp", "D:\\保存到远程.wps", "保存到远程.wps", false);
            alert(aa);
        },
        saveURL2() {    //保存到远程_pdf加密
            var name = prompt("请输入要保存的名称", "test1.ofd")
            if (name != null && name != "") {
                var ret = DocFrame.saveURL("http://192.168.158.73:8080/wps/upload_w.jsp", name, "aa", "bb");
                alert(ret);
            }
        },
        saveURL3() {    //保存到远程_包含设置pdf选项
            // var pdfOptions = DocFrame.get_PdfExportOptions(); 
            // var ret = pdfOptions.put_ConvertSummaryInfo(false); 
            //通过设置ConvertSummaryInfo的值控制是否导出文档信息
            DocFrame.ActiveDocument.Application.PdfExportOptions.ConvertSummaryInfo = false;
            var name = prompt("请输入要保存的名称", "test1.ofd");
            if (name != null && name != "") {
                var ret = DocFrame.saveURL("http://192.168.158.73:8080/wps/upload_w.jsp", name, "aa", "bb");
                alert(ret);
            }

        },
        saveURL4() {    //保存到远程_导出pdf嵌入字体
            var aa = DocFrame.saveURL("http://192.168.41.128:8080/wps/upload_w.jsp", "aa测试.ofd", "", "", true);
            alert(aa);
        },
        DownLoadServerFile() {  //下载
            var aa = DocFrame.DownLoadServerFile("http://192.168.41.128:8080/wps/保存到远程.wps", "D:\\保存到远程2.wps");
            alert(aa);
        },
        setToolbarAllVisibleF() {   //隐藏全部工具菜单
            var aa = DocFrame.setToolbarAllVisible(false);
        },
        setToolbarAllVisibleT() {   //显示全部工具菜单
            var aa = DocFrame.setToolbarAllVisible(true);
        },
        SetFileSubmenuItemsVisible(item) {
            DocFrame.FileSubmenuItems |= item;
        },
        SetFileSubmenuItemsVisible_new() {  //显示新建
            this.SetFileSubmenuItemsVisible(FileSubmenuItems.NEW);
        },
        SetFileSubmenuItemsVisible_open() { //显示打开
            this.SetFileSubmenuItemsVisible(FileSubmenuItems.OPEN);
        },
        SetFileSubmenuItemsVisible_close() {  //显示关闭
            this.SetFileSubmenuItemsVisible(FileSubmenuItems.CLOSE);
        },
        SetFileSubmenuItemsVisible_save() { //显示保存
            this.SetFileSubmenuItemsVisible(FileSubmenuItems.SAVE);
        },
        SetFileSubmenuItemsVisible_saveAs() {   //显示另存
            this.SetFileSubmenuItemsVisible(FileSubmenuItems.SAVEAS);
        },
        SetFileSubmenuItemsVisible_pageSetup() {    //显示页面设置
            this.SetFileSubmenuItemsVisible(FileSubmenuItems.PAGESETUP);
        },
        SetFileSubmenuItemsVisible_printpy() {  //显示打印预览
            this.SetFileSubmenuItemsVisible(FileSubmenuItems.PRINTPY);
        },
        SetFileSubmenuItemsVisible_print() {    //显示打印
            this.SetFileSubmenuItemsVisible(FileSubmenuItems.PRINT);
        },
        SetFileSubmenuItemsVisible_property() { //显示属性
            this.SetFileSubmenuItemsVisible(FileSubmenuItems.PROPERTY);
        },
        SetFileSubmenuItemsHidden(item) {
            DocFrame.FileSubmenuItems &= ~item;
        },
        SetFileSubmenuItemsHidden_new() {   //隐藏新建
            this.SetFileSubmenuItemsHidden(FileSubmenuItems.NEW);
        },
        SetFileSubmenuItemsHidden_open() {   //隐藏打开
            this.SetFileSubmenuItemsHidden(FileSubmenuItems.OPEN);
        },
        SetFileSubmenuItemsHidden_close() {   //隐藏关闭
            this.SetFileSubmenuItemsHidden(FileSubmenuItems.CLOSE);
        },
        SetFileSubmenuItemsHidden_save() {   //隐藏保存
            this.SetFileSubmenuItemsHidden(FileSubmenuItems.SAVE);
        },
        SetFileSubmenuItemsHidden_saveAs() {   //隐藏另存
            this.SetFileSubmenuItemsHidden(FileSubmenuItems.SAVEAS);
        },
        SetFileSubmenuItemsHidden_pageSetup() {   //隐藏页面设置
            this.SetFileSubmenuItemsHidden(FileSubmenuItems.PAGESETUP);
        },
        SetFileSubmenuItemsHidden_printpy() {   //隐藏打印预览
            this.SetFileSubmenuItemsHidden(FileSubmenuItems.PRINTPY);
        },
        SetFileSubmenuItemsHidden_print() {   //隐藏打印
            this.SetFileSubmenuItemsHidden(FileSubmenuItems.PRINT);
        },
        SetFileSubmenuItemsHidden_property() {   //隐藏属性
            this.SetFileSubmenuItemsHidden(FileSubmenuItems.PROPERTY);
        },
    }
}
</script>

<style scoped>
#test {
    display: flex;
    flex-direction: row;
    height: 100%
}
#side-menu {
    overflow: scroll;
    background: #eeeeee;
}
#wps-content {
    margin-left: 5%;
    margin-right: 5%;
    width: 80%;
    height: 100%;
}
#wps {
    height: 80%;
}
#left-menu {
    height: 100%;
}
</style>